package org.imlinker.util;

import java.util.Comparator;

@SuppressWarnings("unchecked")
public class AlphaComparator implements Comparator {

	@Override
	public int compare(Object a, Object b) {

		if (a instanceof String && b instanceof String) {
			String as = a.toString();
			String bs = b.toString();

			for (int i = 0; i < as.length(); i++) {
				if (bs.length() == i) {
					return -1;
				} else if (as.charAt(i) != bs.charAt(i)) {
					return as.charAt(i) - bs.charAt(i);
				}
			}
		}

		return 0;
	}

}
